
** PERSONALITY MEASURES **

	// Conscientiousness

		foreach p in b e {

		* Variables
			summ cnsc_prepare_`p' cnsc_details_`p' cnsc_doitright_`p' cnsc_plans_`p' cnsc_getby_`p' cnsc_work_`p' cnsc_shirk_`p' cnsc_complete_`p'

		* Positive questions: Change to 0-Really Disagree 1-Disagree 2-Agree 3-Really Agree
			foreach var in cnsc_prepare cnsc_details cnsc_doitright cnsc_plans cnsc_getby {
				local lab: var lab `var'_`p'
				gen `var'_resc_`p' = `var'_`p'*-1+4
				la var `var'_resc_`p' "`lab' (Rescaled)"
			}

		* Negative question : Change to 0-Really Agree 1-Agree 2-Disagree 3-Really Disagree
			foreach var in cnsc_work cnsc_shirk cnsc_complete {
				local lab: var lab `var'_`p'
				gen `var'_resc_`p' = `var'_`p'-1
				la var `var'_resc_`p' "`lab'"
			}

		* Analyze responses
			summ cnsc_prepare_resc_`p' cnsc_details_resc_`p' cnsc_doitright_resc_`p' cnsc_plans_resc_`p' cnsc_getby_resc_`p' cnsc_work_resc_`p' cnsc_shirk_resc_`p' cnsc_complete_resc_`p'
			pwcorr cnsc_prepare_resc_`p' cnsc_details_resc_`p' cnsc_doitright_resc_`p' cnsc_plans_resc_`p' cnsc_getby_resc_`p' cnsc_work_resc_`p' cnsc_shirk_resc_`p' cnsc_complete_resc_`p'
			factor cnsc_prepare_resc_`p' cnsc_details_resc_`p' cnsc_doitright_resc_`p' cnsc_plans_resc_`p' cnsc_getby_resc_`p' cnsc_work_resc_`p' cnsc_shirk_resc_`p' cnsc_complete_resc_`p'

		* Generate declared Conscientiousness index
			egen conscientious_`p' = rowtotal(cnsc_prepare_resc_`p' cnsc_details_resc_`p' cnsc_doitright_resc_`p' cnsc_plans_resc_`p' cnsc_getby_resc_`p' cnsc_work_resc_`p' cnsc_shirk_resc_`p' cnsc_complete_resc_`p'), m
				la var conscientious_`p' "Conscientiousness Index (0-23) Add index of 8 survey questions"

		* Generate versions of the index that separate high and low empahsis questions

			egen conscientious_g1_`p' = rowtotal(cnsc_details_resc_`p' cnsc_plans_resc_`p' cnsc_shirk_resc_`p' cnsc_complete_resc_`p'), m
				la var conscientious_g1_`p' "Conscientiousness indicator, emphasis greater than 1" /// See "variable construction/CBT Training Emphasis.xlsx"

			egen conscientious_le1_`p' = rowtotal(cnsc_prepare_resc_`p' cnsc_doitright_resc_`p' cnsc_work_resc_`p' cnsc_getby_resc_`p'), m
				la var conscientious_le1_`p' "Conscientiousness indicator, emphasis greater than 1" /// See "variable construction/CBT Training Emphasis.xlsx"

			egen conscientious_g15_`p' = rowtotal(cnsc_plans_resc_`p' cnsc_shirk_resc_`p' cnsc_complete_resc_`p'), m
				la var conscientious_g15_`p' "Conscientiousness indicator, emphasis greater than 1.5" /// See "variable construction/CBT Training Emphasis.xlsx"

			egen conscientious_le15_`p' = rowtotal(cnsc_details_resc_`p' cnsc_prepare_resc_`p' cnsc_doitright_resc_`p' cnsc_work_resc_`p' cnsc_getby_resc_`p'), m
				la var conscientious_le15_`p' "Conscientiousness indicator, emphasis greater than 1.5" /// See "variable construction/CBT Training Emphasis.xlsx"

			egen conscientious_g2_`p' = rowtotal(cnsc_plans_resc_`p'), m
				la var conscientious_g2_`p' "Conscientiousness indicator, emphasis greater than 2" /// See "variable construction/CBT Training Emphasis.xlsx"

			egen conscientious_le2_`p' = rowtotal(cnsc_details_resc_`p' cnsc_prepare_resc_`p' cnsc_doitright_resc_`p' cnsc_work_resc_`p' cnsc_getby_resc_`p'  cnsc_shirk_resc_`p' cnsc_complete_resc_`p'), m
				la var conscientious_le2_`p' "Conscientiousness indicator, emphasis greater than 2" /// See "variable construction/CBT Training Emphasis.xlsx"

		}




	// Grit/Perserverence

		 foreach p in b e {

		* Variables
			summ prsv_overcome_`p' prsv_ambitious_`p' prsv_discourage_`p' prsv_achieveimp_`p' prsv_driven_`p' prsv_changeplan_`p' prsv_achievenoimp_`p'

		* Positive questions: Change to 0-Really Disagree 1-Disagree 2-Agree 3-Really Agree
			foreach var in prsv_overcome prsv_ambitious prsv_discourage prsv_achieveimp prsv_driven {
				local lab: var lab `var'_`p'
				gen `var'_resc_`p' = `var'_`p'*-1+4
				la var `var'_resc_`p' "`lab' (Rescaled)"
			}

		* Negative question : Change to 0-Really Agree 1-Agree 2-Disagree 3-Really Disagree
			foreach var in prsv_changeplan prsv_achievenoimp {
				local lab: var lab `var'_`p'
				gen `var'_resc_`p' = `var'_`p'-1
				la var `var'_resc_`p' "`lab'"
			}

		* Analyze responses
			summ prsv_overcome_resc_`p' prsv_ambitious_resc_`p' prsv_discourage_resc_`p' prsv_achieveimp_resc_`p' prsv_driven_resc_`p' prsv_changeplan_resc_`p' prsv_achievenoimp_resc_`p'
			pwcorr prsv_overcome_resc_`p' prsv_ambitious_resc_`p' prsv_discourage_resc_`p' prsv_achieveimp_resc_`p' prsv_driven_resc_`p' prsv_changeplan_resc_`p' prsv_achievenoimp_resc_`p'
			factor prsv_overcome_resc_`p' prsv_ambitious_resc_`p' prsv_discourage_resc_`p' prsv_achieveimp_resc_`p' prsv_driven_resc_`p' prsv_changeplan_resc_`p' prsv_achievenoimp_resc_`p'

		* Generate declared perseverance index
			egen grit_`p' = rowtotal(prsv_overcome_resc_`p' prsv_ambitious_resc_`p' prsv_discourage_resc_`p' prsv_achieveimp_resc_`p' prsv_driven_resc_`p' prsv_changeplan_resc_`p' prsv_achievenoimp_resc_`p'), m
				la var grit_`p' "Perseverance Index (0-7) add index of 7 survey questions"

		* Create second version with low and high emphasis components
			egen grit_g1_`p' = rowtotal(prsv_overcome_resc_`p' prsv_ambitious_resc_`p' prsv_discourage_resc_`p' prsv_achieveimp_resc_`p' prsv_driven_resc_`p' prsv_changeplan_resc_`p' prsv_achievenoimp_resc_`p'), m
				la var grit_g1_`p' "Perseverence indicator, emphasis greater than 1" /// See "variable construction/CBT Training Emphasis.xlsx"

			gen grit_le1_`p' = .
				la var grit_le1_`p' "Perseverence indicator, emphasis less than or equal to 1" /// See "variable construction/CBT Training Emphasis.xlsx"

			egen grit_g15_`p' = rowtotal(prsv_overcome_resc_`p' prsv_ambitious_resc_`p' prsv_discourage_resc_`p' prsv_achieveimp_resc_`p' prsv_changeplan_resc_`p'), m
				la var grit_g15_`p' "Perseverence indicator, emphasis greater than 1.5" /// See "variable construction/CBT Training Emphasis.xlsx"

			egen grit_le15_`p' =  rowtotal(prsv_driven_resc_`p' prsv_achievenoimp_resc_`p'), m
				la var grit_le15_`p' "Perseverence indicator, emphasis less than or equal to 1.5" /// See "variable construction/CBT Training Emphasis.xlsx"

			egen grit_g2_`p' = rowtotal(prsv_overcome_resc_`p' prsv_ambitious_resc_`p' prsv_discourage_resc_`p' prsv_achieveimp_resc_`p' prsv_changeplan_resc_`p'), m
				la var grit_g2_`p' "Perseverence indicator, emphasis greater than 2" /// See "variable construction/CBT Training Emphasis.xlsx"

			egen grit_le2_`p' =  rowtotal(prsv_driven_resc_`p' prsv_achievenoimp_resc_`p'), m
				la var grit_le2_`p' "Perseverence indicator, emphasis less than or equal to 2" /// See "variable construction/CBT Training Emphasis.xlsx"

		}

	// Reward responsiveness

		foreach p in b e {

		* Variables
			summ bas_goallout_`p' bas_noholds_`p' bas_doforfun_`p' bas_keepatit_`p' bas_feelexcite_`p' bas_seeopp_`p' bas_feelstrongly_`p' bas_wincontest_`p'

		* Positive questions: Change to 0-Really Disagree 1-Disagree 2-Agree 3-Really Agree
			foreach var in bas_goallout bas_noholds bas_doforfun bas_keepatit bas_feelexcite bas_seeopp bas_feelstrongly bas_wincontest {
				local lab: var lab `var'_`p'
				gen `var'_resc_`p' = `var'_`p'*-1+4
				la var `var'_resc_`p' "`lab' (Rescaled)"
			}

		* Analyze responses
			summ bas_goallout_resc_`p' bas_noholds_resc_`p' bas_doforfun_resc_`p' bas_keepatit_resc_`p' bas_feelexcite_resc_`p' bas_seeopp_resc_`p' bas_feelstrongly_resc_`p' bas_wincontest_resc_`p'
			pwcorr bas_goallout_resc_`p' bas_noholds_resc_`p' bas_doforfun_resc_`p' bas_keepatit_resc_`p' bas_feelexcite_resc_`p' bas_seeopp_resc_`p' bas_feelstrongly_resc_`p' bas_wincontest_resc_`p'
			factor bas_goallout_resc_`p' bas_noholds_resc_`p' bas_doforfun_resc_`p' bas_keepatit_resc_`p' bas_feelexcite_resc_`p' bas_seeopp_resc_`p' bas_feelstrongly_resc_`p' bas_wincontest_resc_`p'

		* Generate reward responsiveness index
			egen rewardresp_`p' = rowtotal(bas_goallout_resc_`p' bas_noholds_resc_`p' bas_doforfun_resc_`p' bas_keepatit_resc_`p' bas_feelexcite_resc_`p' bas_seeopp_resc_`p' bas_feelstrongly_resc_`p' bas_wincontest_resc_`p'), m
				la var rewardresp_`p' "Reward Responsiveness (0-23) add index of 8 survey questions"

		* Generage reward responsiveness using only low/high emphasis components
			gen rewardresp_g1_`p' = .
				la var rewardresp_g1_`p' "Reward Responsiveness, emphasis greater than 1"
			egen rewardresp_le1_`p' = rowtotal(bas_goallout_resc_`p' bas_noholds_resc_`p' bas_doforfun_resc_`p' bas_keepatit_resc_`p' bas_feelexcite_resc_`p' bas_seeopp_resc_`p' bas_feelstrongly_resc_`p' bas_wincontest_resc_`p'), m
				la var rewardresp_le1_`p' "Reward Responsiveness, emphasis less than or equal to 1"

			gen rewardresp_g15_`p' = .
				la var rewardresp_g15_`p' "Reward Responsiveness, emphasis greater than 1.5"
			egen rewardresp_le15_`p' = rowtotal(bas_goallout_resc_`p' bas_noholds_resc_`p' bas_doforfun_resc_`p' bas_keepatit_resc_`p' bas_feelexcite_resc_`p' bas_seeopp_resc_`p' bas_feelstrongly_resc_`p' bas_wincontest_resc_`p'), m
				la var rewardresp_le15_`p' "Reward Responsiveness, emphasis less than or equal to 1.5"

			gen rewardresp_g2_`p' = .
				la var rewardresp_g2_`p' "Reward Responsiveness, emphasis greater than 2"
			egen rewardresp_le2_`p' = rowtotal(bas_goallout_resc_`p' bas_noholds_resc_`p' bas_doforfun_resc_`p' bas_keepatit_resc_`p' bas_feelexcite_resc_`p' bas_seeopp_resc_`p' bas_feelstrongly_resc_`p' bas_wincontest_resc_`p'), m
				la var rewardresp_le2_`p' "Reward Responsiveness, emphasis less than or equal to 2"

		}

// Impulsiveness
		* Endline p1_e5m p1_e12m p2_e2wks p3_e2w
		* Baseline p3_b p2_b

		foreach p in b e {

		* Variables
			summ bimpls_*_`p' time_decl_hidemoney_`p' time_decl_regretspend_`p'

		* Positive questions: Change to 0-Never 1-One one time 2-Sometimes 3-Everytime
			foreach var in bimpls_present bimpls_buy bimpls_act bimpls_talk bimpls_squirm bimpls_concentrate  {
				local lab: var lab `var'_`p'
				gen `var'_resc_`p' = `var'_`p'*-1+4
				la var `var'_resc_`p' "`lab' (Rescaled)"
			}

		* Negative question : Change to 0-Everytime 1-Sometimes 2-One one time 3-Never
			foreach var in bimpls_control {
				local lab: var lab `var'_`p'
				gen `var'_resc_`p' = `var'_`p'-1
				la var `var'_resc_`p' "`lab'"
			}

		* Analyze responses
			summ bimpls_buy_resc_`p' bimpls_act_resc_`p' bimpls_talk_resc_`p' bimpls_squirm_resc_`p' bimpls_concentrate_resc_`p' bimpls_present_resc_`p' bimpls_control_resc_`p' time_decl_hidemoney_resc_`p' time_decl_regretspend_resc_`p'
			pwcorr bimpls_buy_resc_`p' bimpls_act_resc_`p' bimpls_talk_resc_`p' bimpls_squirm_resc_`p' bimpls_concentrate_resc_`p' bimpls_present_resc_`p' bimpls_control_resc_`p' time_decl_hidemoney_resc_`p' time_decl_regretspend_resc_`p'
			factor bimpls_buy_resc_`p' bimpls_act_resc_`p' bimpls_talk_resc_`p' bimpls_squirm_resc_`p' bimpls_concentrate_resc_`p' bimpls_present_resc_`p' bimpls_control_resc_`p' time_decl_hidemoney_resc_`p' time_decl_regretspend_resc_`p'
				rotate
				summ bimpls_buy_resc_`p' bimpls_act_resc_`p' bimpls_talk_resc_`p' bimpls_squirm_resc_`p' bimpls_concentrate_resc_`p' bimpls_present_resc_`p' bimpls_control_resc_`p' time_decl_hidemoney_resc_`p' time_decl_regretspend_resc_`p'

		* Generate declared impulsiveness index
			gen impulsive_`p' = bimpls_buy_resc_`p' + bimpls_act_resc_`p' + bimpls_talk_resc_`p' + bimpls_squirm_resc_`p' + bimpls_concentrate_resc_`p' + bimpls_present_resc_`p' + bimpls_control_resc_`p' + time_decl_regretspend_resc_`p'
				la var impulsive_`p' "Impulviveness Index (0-20) Add index of 8 survey questions"

			bysort phase round: summ impulsive_`p'

		* Make separate version with low and high emphasis components
			gen impulsive_g1_`p' = bimpls_buy_resc_`p' + bimpls_act_resc_`p' + bimpls_talk_resc_`p' + bimpls_present_resc_`p' + bimpls_control_resc_`p'
				la var impulsive_g1_`p' "Impulsiveness indicator, emphasis greater than 1" /// See "variable construction/CBT Training Emphasis.xlsx"

			gen impulsive_le1_`p' = bimpls_squirm_resc_`p' + bimpls_concentrate_resc_`p' + time_decl_regretspend_resc_`p'
				la var impulsive_le1_`p' "Impulsiveness indicator, emphasis less than or equal to 1" /// See "variable construction/CBT Training Emphasis.xlsx"

			gen impulsive_g15_`p' = bimpls_buy_resc_`p' + bimpls_act_resc_`p' + bimpls_present_resc_`p' + bimpls_control_resc_`p'
				la var impulsive_g15_`p' "Impulsiveness indicator, emphasis greater than 1.5" /// See "variable construction/CBT Training Emphasis.xlsx"

			gen impulsive_le15_`p' = bimpls_squirm_resc_`p' + bimpls_concentrate_resc_`p' + time_decl_regretspend_resc_`p' + bimpls_talk_resc_`p'
				la var impulsive_le15_`p' "Impulsiveness indicator, emphasis less than or equal to 1.5" /// See "variable construction/CBT Training Emphasis.xlsx"

			gen impulsive_g2_`p' = bimpls_buy_resc_`p' + bimpls_act_resc_`p' + bimpls_present_resc_`p' + bimpls_control_resc_`p'
				la var impulsive_g2_`p' "Impulsiveness indicator, emphasis greater than 2" /// See "variable construction/CBT Training Emphasis.xlsx"

			gen impulsive_le2_`p' = bimpls_squirm_resc_`p' + bimpls_concentrate_resc_`p' + time_decl_regretspend_resc_`p' + bimpls_talk_resc_`p'
				la var impulsive_le2_`p' "Impulsiveness indicator, emphasis less than or equal to 2" /// See "variable construction/CBT Training Emphasis.xlsx"

		}

 	// DELAY OF GRATIFICATION

		* Water Games (p1_b only)

			* Time takes Water  (minutes after 00:00)
				gen watertakemin_b =  wg_g1hh_b*60 +  wg_g1hm_b if wg_g1hapm_b == "AM" | (wg_g1hapm_b == "PM" & wg_g1hh_b == 12)
				replace watertakemin_b = (wg_g1hh_b+12)*60 +  wg_g1hm_b if wg_g1hapm_b == "PM"  & wg_g1hh_b != 12
					la var watertakemin_b "Water: Time takes Water  (minutes after 00:00)"

			* Times to take Water
				gen timestotakewater_b = watertakemin_b - gamestart_b if p1==1
				replace timestotakewater_b = 0 if watertakemin_b ==. & p1==1
					la var timestotakewater_b "Water: Time to take water"

			* 1 if took the water
				gen timestotakewaterdum_b = (timestotakewater_b!=0 & timestotakewater_b!=.) if p1==1
					la var timestotakewaterdum_b "Water: 1 if took the water"

				egen timestotakewaterstd_b =std(timestotakewater_b) if p1==1


		* Soft drink

			* Interview start (minutes after 00:00)
				gen datestartmin_b= datestarth_b*60 + datestartm_b
					la var datestartmin_b "Interviw start (minutes after 00:00)"

			* Time to take Soft Drink (minutes after 00:00)
				gen sdtakemin_b =  sdchoosechecktimeh_b*60 +  sdchoosechecktimem_b
					la var sdtakemin_b "Soft Drink: Time takes Water  (minutes after 00:00)"

			* Time to take the soft drink
				gen timestotakesd_b =  sdtakemin_b - datestartmin_b if p2==1  & sdtakemin_b!=.
				replace timestotakesd_b = . if timestotakesd_b <0
				replace timestotakesd_b = 0 if sdchoosecheck_b==1
				la var timestotakesd_b "Soft Drink: Time to take soft drink"

			* Took Soft drink
				foreach p in b e {

					* Variables
					cap summ drinktoday_`p' drinktodaytime_`p' eattoday_`p' eattodaytime_`p' sdflavor_`p' sdthirsty_`p' sdbottle_`p' sdtaste_`p' sdchoose_`p' sdchoosecheck_`p' sdchoosechecktime_`p'

					gen take_drink_`p' = (sdchoosecheck_`p'*-1)+3
						la var take_drink_`p' "Took soft drink (0=end, 1=middle, 2=beginning)"

					bysort phase round: summ take_drink_`p'

				}






		/*
		/* Construct aggregate measure with only high/low emphasis */
		foreach z in g1 g15 g2 le1 le15 le2 {
			/* Standardize personality measures */
				foreach x in impulsive  rewardresp conscientious grit {
					local lbl : variable label `x'_`z'_e
					egen `x'std`z'_e = std(`x'_`z'_e)
					replace `x'std`z'_e=. if `x'_`z'_e==.
					la var `x'std`z'_e "`lbl' (Z-Score)"

				}
			/* Rescale personality measures that are negative */
				foreach x in impulsive rewardresp {
					gen `x'std`z'_resc_e = -`x'std`z'_e
					la var `x'std`z'_resc_e "Rescaled: `: var lab `x'std`z'_e'"
				}
			egen personalitystd`z'_e = rowmean(impulsivestd`z'_resc_e rewardrespstd`z'_resc_e conscientiousstd`z'_e gritstd`z'_e)
				sum personalitystd`z'_e
				qui replace personalitystd`z'_e = (personalitystd`z'_e-r(mean))/r(sd)
				la var personalitystd`z'_e "Standardized Index of Personality Measures (restricted emphasis - `z')"

		}
